
#include "includes.h"
#include "structs.h"
#include "declares.h"

void *sleeping(void *p)
{
        int i=p;
        printf("thread %d is sleeping for %d s\n", i,i);
        sleep(i);
        pthread_exit(p);
}

int main(int ac, char**av)
{
       int nfrag=4; 
        for(int i=0;i<nfrag;++i) {
                reset_timer(LOAD_TIMER);
                pthread_create(&grape_var.threads[i], &grape_var.joinable_attr,
                                sleeping, (void*) i);
                stop_timer(LOAD_TIMER);
                printf("thread %d spent %lf s in sleeping\n", i, get_timer(LOAD_TIMER));
        }

        
        for(int i=0;i<nfrag;++i) {
                pthread_join(grape_var.threads[i], NULL);
        }

}
